//
//  ControlPeriods.m
//  FishTank
//
//  Created by Scott Zhu on 14/12/10.
//  Copyright (c) 2014年 Scott Zhu. All rights reserved.
//

#import "ControlPeriods.h"

@implementation ControlPeriods

-(instancetype)initWithPeriodData:(char *)periodData
{
    self = [self init];
    if (self)
    {
        if (nil == periodData) return self;
        
        self.period1.startHour = periodData[0] & 31;//31 == 0001 1111
        self.period1.startMinute = (unsigned char)periodData[0] >> 5;
        self.period1.endHour = periodData[1] & 31;
        self.period1.endMinutes = (unsigned char)periodData[1] >> 5;
        
        self.period2.startHour = periodData[2] & 31;//31 == 0001 1111
        self.period2.startMinute = (unsigned char)periodData[2] >> 5;
        self.period2.endHour = periodData[3] & 31;
        self.period2.endMinutes = (unsigned char)periodData[3] >> 5;
        
        self.period3.startHour = periodData[4] & 31;//31 == 0001 1111
        self.period3.startMinute = (unsigned char)periodData[4] >> 5;
        self.period3.endHour = periodData[5] & 31;
        self.period3.endMinutes = (unsigned char)periodData[5] >> 5;
        
    }
    return self;
}

-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self.period1 = [[Period alloc] init];
        self.period2 = [[Period alloc] init];
        self.period3 = [[Period alloc] init];
        self.type = -1;
    }
    return self;
}

- (void)data:(char *)data
{
    if (nil == data) return;
    data[0] = ((char)self.period1.startMinute << 5) | (char)self.period1.startHour;
    data[1] = ((char)self.period1.endMinutes << 5) | (char)self.period1.endHour;
    
    data[2] = ((char)self.period2.startMinute << 5) | (char)self.period2.startHour;
    data[3] = ((char)self.period2.endMinutes << 5) | (char)self.period2.endHour;
    
    data[4] = ((char)self.period3.startMinute << 5) | (char)self.period3.startHour;
    data[5] = ((char)self.period3.endMinutes << 5) | (char)self.period3.endHour;
}

@end
